package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.StudentTime;
import com.ruoyi.system.domain.UpdateAttend;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ClaTimeAttend;
import com.ruoyi.system.service.IClaTimeAttendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 上课出勤Controller
 * 
 * @author ZHANGQIBO
 * @date 2024-01-21
 */
@RestController
@RequestMapping("/system/attend")
@Transactional(rollbackFor = Exception.class)
public class ClaTimeAttendController extends BaseController
{
    @Autowired
    private IClaTimeAttendService claTimeAttendService;

    /**
     * 查询上课出勤列表
     */
    @PreAuthorize("@ss.hasPermi('system:attend:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClaTimeAttend claTimeAttend)
    {
        startPage();
        List<StudentTime> list = claTimeAttendService.selectClaTimeAttendList(claTimeAttend);
        return getDataTable(list);
    }
    /**
     * 查询上课出勤列表
     */
    @PreAuthorize("@ss.hasPermi('system:attend:list')")
    @PostMapping("/SinglelistAPP")
    public AjaxResult SinglelistAPP(@RequestBody ClaTimeAttend claTimeAttend)
    {
        List<StudentTime> list = claTimeAttendService.selectClaTimeAttendListAPP(claTimeAttend);
        return AjaxResult.success(list);
    }



    /**
     * 获取上课出勤详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attend:query')")
    @GetMapping(value = "/{attendId}")
    public AjaxResult getInfo(@PathVariable("attendId") Long attendId)
    {
        return AjaxResult.success(claTimeAttendService.selectClaTimeAttendByAttendId(attendId));
    }

    /**
     * 新增上课出勤
     */
    @PreAuthorize("@ss.hasPermi('system:attend:add')")
    @Log(title = "上课出勤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClaTimeAttend claTimeAttend)
    {
        return toAjax(claTimeAttendService.insertClaTimeAttend(claTimeAttend));
    }

    /**
     * 修改上课出勤
     */
    @PreAuthorize("@ss.hasPermi('system:attend:edit')")
    @Log(title = "上课出勤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClaTimeAttend claTimeAttend)
    {
        return toAjax(claTimeAttendService.updateClaTimeAttend(claTimeAttend));
    }
    /**
     * 新增app上课出勤
     */
//    @PreAuthorize("@ss.hasPermi('system:attend:add')")
    @Log(title = "上课出勤", businessType = BusinessType.INSERT)
    @PostMapping("/addAttend")
    public AjaxResult QUANadd(@RequestBody ClaTimeAttend claTimeAttend)
    {
        return toAjax(claTimeAttendService.insertQuanClaTimeAttend(claTimeAttend));
    }

    /**
     * 修改app上课出勤
     */
//    @PreAuthorize("@ss.hasPermi('system:attend:edit')")
    @Log(title = "上课出勤", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAttend")
    public AjaxResult QUANedit(@RequestBody UpdateAttend updateAttend)
    {

        return toAjax(claTimeAttendService.updateQuanClaTimeAttend(updateAttend));
    }

    /**
     * 删除上课出勤
     */
    @PreAuthorize("@ss.hasPermi('system:attend:remove')")
    @Log(title = "上课出勤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attendIds}")
    public AjaxResult remove(@PathVariable Long[] attendIds)
    {
        return toAjax(claTimeAttendService.deleteClaTimeAttendByAttendIds(attendIds));
    }
}
